<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="李愧愧">
    <title></title>
    <style>
        .box{
            width: 600px;
            height: 200px;
            background-color: burlywood;
            margin: 0 auto;
        }
        .box1{
            border: 1px solid gray;
            width: 150px;
            height: 25px;
            text-align: center;
            line-height: 25px;
            font-size: 13px;
            background-color: #e5e5e5;
            margin: auto;
        }
        .box2{
            width: 360px;
            margin: auto;
            margin-top: 10px;
        }
        .a{
            width: 100px;
            height: 100px;
            float: left;
            background-color: black;
            margin-left: 20px;

        }
        .box2 .a:nth-of-type(1){
            margin-left: 0px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="box1">
            点击将DIV变成红色
        </div>
        <div class="box2">
            <div class="a"></div>
            <div class="a"></div>
            <div class="a"></div>
        </div>
    </div>
<script>
    var box1=document.querySelector('.box1');
    var a=document.querySelectorAll('.a');
    box1.onclick=function(ev){
        for(var i = 0; i < 3; i++){
            a[i].style='background-color: red;'
        }
        ev.stopPropagation();
    }
    document.onclick=function(){
        a.style='background-color: black;'
    }

</script>
</body>
</html>